import {IVector2} from "./types";

export class MathUtil {
    static clamp(value: number, min: number, max: number) {
        return Math.min(max, Math.max(min, value));
    }

    static setPointToScreenRange(point: IVector2, width: number, height: number) {
        point.x = MathUtil.clamp(Math.round(point.x), 0, width-1);
        point.y = MathUtil.clamp(Math.round(point.y), 0, height-1);
    }

    static roundPoint2D(p: IVector2) {
        p.x = Math.round(p.x);
        p.y = Math.round(p.y);
    }
}